<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['basic']=$basic;
$return['banner']=$basic['image'];
if($_RQ['op']=='main'){
	$isfee=intval($_RQ['isfee']);
	//其实要展示的信息为课程信息
	if($_RQ['lessonid']){
		$lesson=pdo_get('jy_kexie_lesson',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['lessonid']));
	}
	//查询本项目可服务员工(未锁定，状态为可服务)
	$worker_list=pdo_getall('jy_kexie_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$lesson['workerid']));
	//查询本项目的访问人数及添加访问人数
	/*
	$num=pdo_getcolumn('jy_kexie_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'num');
	$serve['num']=$num+1;
	pdo_update('jy_kexie_serve',array('num'=>$serve['num']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//已支付，已确认，已完成订单数
	$num1=pdo_count('jy_kexie_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$_RQ['id'],'status'=>'1'));
	$num2=pdo_count('jy_kexie_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$_RQ['id'],'status'=>'2'));
	$num3=pdo_count('jy_kexie_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$_RQ['id'],'status'=>'4'));
	$serve['ordernum']=$num1+$num2+$num3;
	$serve_time=json_decode($serve['serve_time'],true);
	*/
	//日期 今天，未来七天
	$data=array();
	$data['0']['riqi']=date("m-d",time("day")); 
	$data['1']['riqi']=date("m-d",strtotime("+1 day")); 
	$data['2']['riqi']=date("m-d",strtotime("+2 day")); 
	$data['3']['riqi']=date("m-d",strtotime("+3 day")); 
	$data['4']['riqi']=date("m-d",strtotime("+4 day")); 
	$data['5']['riqi']=date("m-d",strtotime("+5 day")); 
	$data['6']['riqi']=date("m-d",strtotime("+6 day")); 
	$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
	$data['0']['xinq']= "周".$weekarray[date("w")];
	$data['1']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+1 day"))))];
	$data['2']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+2 day"))))];
	$data['3']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+3 day"))))];
	$data['4']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+4 day"))))];
	$data['5']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+5 day"))))];
	$data['6']['xinq']= "周".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+6 day"))))];
	
	//$this->session('serve_id',$_RQ['id']);
	
	//获取当前时间
	/*
	$time=time();
	foreach($serve_time as $k=>&$item){
		$num=pdo_count('jy_kexie_order',array('timeid'=>$k,'uniacid'=>$_SESSION['uniacid'],'day'=>date("Y-m-d",time("day")),'serve_id'=>$_RQ['id']));
		
		if($item['yuyue']>$num){
		$item['yuyue']=$item['yuyue']-$num;
		}
		else{
		$item['yuyue']=0;
		}
		//时间转为时间戳
		$item['shijian']=strtotime(date("Y-m-d",time("day")).$item['times']['start']);
		if($item['shijian']<time()){
			$item['show']=0;
		}
		else{
			$item['show']=1;
		}
	}
	*/
	$return['storetitle']=pdo_getcolumn('jy_kexie_store',array('id'=>$class['storeid']),'title');
	$return['lessons']=$list;
	//$return['package']=json_decode($package);
	$return['worker_list']=$worker_list;
	$return['data']=$data;
	$return['post']=array('lessonid'=>$_RQ['lessonid'],'storeid'=>$class['storeid'],'isfee'=>$isfee);
	exi($return);
}
if($_RQ['op']=='yuyue'){
	$postdata=get_postdata();
	//日期 今天，未来七天
	$data=array();
	$data['0']=date("Y-m-d",time("day")); 
	$data['1']=date("Y-m-d",strtotime("+1 day")); 
	$data['2']=date("Y-m-d",strtotime("+2 day")); 
	$data['3']=date("Y-m-d",strtotime("+3 day")); 
	$data['4']=date("Y-m-d",strtotime("+4 day")); 
	$data['5']=date("Y-m-d",strtotime("+5 day")); 
	$data['6']=date("Y-m-d",strtotime("+6 day"));
	$lessonid=intval($_RQ['lessonid']);
	//单课程,还未上课完的
	if($postdata['lessonid']){
		$iseduing=pdo_getcolumn('jy_kexie_order',array('lesson_id'=>$postdata['lessonid'],'status'=>array(1,2),'ispay'=>1,'bodyid'=>$postdata['bodyid'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	}else{
		$iseduing=pdo_getcolumn('jy_kexie_order',array('classid'=>$postdata['classid'],'status'=>array(1,2),'ispay'=>1,'bodyid'=>$postdata['bodyid'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	}
	if(!$iseduing){
		exi('','','jy_kexie/create//storeid='.$postdata['storeid'].'&classid='.$postdata['classid'].'&lessonid='.$postdata['lessonid'].'&dayid='.$postdata['dayid'].'&isfee='.$postdata['isfee']);
	}
	$workerid=intval($_RQ['workerid']);
	if($postdata){
			//$time=ijson_encode(array('data'=>$postdata['data'],'start'=>$postdata['start'],'end'=>$postdata['end']));	
			$isllog=pdo_getcolumn('jy_kexie_lesson_log',array('uniacid'=>$_SESSION['uniacid'],'lesson_id'=>$lessonid,'bodyid'=>$postdata['bodyid'],'day'=>$data[$postdata['dayid']]),'id');
			if($isllog){
				exi('该学生已经预约了当天的该课程！','error');
			}
			//查询当日课程		
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'bodyid'=>$postdata['bodyid'],
				'lesson_id'=>$lessonid,
				'classid'=>$postdata['classid'],
				'day'=>$data[$postdata['dayid']],
				'worker_id'=>$workerid,
				'remark'=>$postdata['remark'],
				'logsn'=>get_ordersn('jy_kexie_lesson_log','logsn'),
				'ontime'=>ijson_encode(array('start'=>$_RQ['start'],'end'=>$_RQ['end'])),
				'createtime'=>TIMESTAMP,
				'storeid'=>$postdata['storeid']
			);
			pdo_insert('jy_kexie_lesson_log',$insert);
			$id=pdo_insertid();
			exi('预约课程成功！','','jy_kexie/mylesson_log/');
	}
	
}
if($_RQ['op']=='get_lesson'){
	if(!isset($_RQ['dayid'])){
		exi('请重新选择日期','error');
	}
	$return['list']=$list;
	$return['success']=1;
	
	exi($return);
}